package net.wangds.data.impl;


import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.SuperBuilder;
import net.wangds.data.*;
import net.wangds.data.ann.ColumnDef;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;

@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@MappedSuperclass
public abstract class WithIdImpl implements WithId<String>, Removable, Lockable, Serializable {

    private static final long serialVersionUID = 0;

    @Getter
    @Setter
    @Id
    @GenericGenerator(name = "user-uuid", strategy = "uuid")
    @GeneratedValue(generator = "user-uuid")
    @Column(name="id", length = 36)
    @org.springframework.data.annotation.Id
    @ColumnDef(displayname = "记录唯一标识", dataType = DataTypeEnum.Text,
            colDataType = ColumnOrientedDataTypeEnum.Text, memo = "varchar(36)")
    @ApiModelProperty("记录唯一标识")
    private String id;


    @Getter
    @Setter
    @Builder.Default
    @ColumnDef(displayname = "是否删除", dataType = DataTypeEnum.Number,
            colDataType = ColumnOrientedDataTypeEnum.Int, memo = "0:正常,1:删除.")
    @ApiModelProperty("是否已经删除")
    private RemovedEnum removed = RemovedEnum.NORMAL;


    @Override
    public String buildLockKey() {
        return this.id;
    }
}
